package org.dromara.job.snailjob;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import com.aizuda.snailjob.common.core.util.JsonUtil;
import com.aizuda.snailjob.common.log.SnailJobLog;
import org.dromara.common.json.utils.JsonUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 正常任务
 * <a href="https://juejin.cn/post/7418074037392293914"></a>
 *
 * @author 老马
 */
@Component
@JobExecutor(name = "testJobExecutor")
public class TestAnnoJobExecutor {

    public ExecuteResult jobExecute(JobArgs jobArgs) {
        SnailJobLog.LOCAL.info("testJobExecutor. jobArgs:{}", JsonUtil.toJsonString(jobArgs));
        SnailJobLog.REMOTE.info("testJobExecutor. jobArgs:{}", JsonUtil.toJsonString(jobArgs));
        return ExecuteResult.success("测试成功");
    }

    public static void main(String[] args) {
        // 请求参数
        String url = "https://api.wbzzsf.com.cn/member/queryMemberList";
        String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDk0Njk1MDAsInN1YiI6IntcImRhdGFcIjp7XCJwcmVzZW50bGltaXRtb250aFwiOjAsXCJjcmVhdGVVc2VySWRcIjoxMzAwLFwicHJhY3RpY2VcIjowLFwiYm9zc2xvZ2luYWxsb3dcIjowLFwidHlwZVwiOjAsXCJkZWxldGVGbGFnXCI6MCxcInBhc3Njb21wbGV4XCI6MCxcImlmY2FzaGllcmxvZ2luXCI6ZmFsc2UsXCJsYXN0c3VibWl0dGltZVwiOjE3NDI1MjY4MDgsXCJwYXNzd29yZFwiOlwiZTQ2ODY1NGUwMjM0YThjZjRjZGY4ODBiMzIzZmY3YzhcIixcImNvbnRyaWJ1dGlvblwiOjAsXCJzZW5kY29kZVwiOjAsXCJzY3JlZW5TaG93XCI6MCxcInN0YXRlXCI6dHJ1ZSxcImRhd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pblwiOjAsXCJpc0N1c3RvbWVyQWNjb3VudFwiOjAsXCJhY2NvdW50XCI6XCLpnZLmoZTms7Dlr4zlupflkKflj7BcIixcInF1YWxpZmllZFJhdGVcIjowLjB9LFwic291cmNlXCI6MixcInNwYWNlXCI6W1wiQ0FTSElFUlwiXSxcInVzZXJcIjp7XCJhY2NvdW50XCI6XCLpnZLmoZTms7Dlr4zlupflkKflj7BcIixcImF2YXRhclwiOlwiXCIsXCJnaWRcIjoyMDM3OCxcImlkY2FyZFwiOlwi6Z2S5qGU5rOw5a-M5bqX5ZCn5Y-wXCIsXCJwaG9uZVwiOlwiXCIsXCJyb2xlTmFtZVwiOlwi5ZCn5Y-w5LiT55SoXCIsXCJyb2xlaWRcIjoyMzEyLFwidHlwZVwiOjAsXCJ1bmlhY2lkXCI6MjAxNTUsXCJ1c2VySWRcIjo3NTAyLFwidXNlck5hbWVcIjpcIumdkuahlOazsOWvjOW6l-WQp-WPsFwifSxcInVzZXJJZFwiOjc1MDJ9IiwiZXhwIjoxNzQ5NTc3NTAwLCJuYmYiOjE3NDk0Njk1MDB9._8JTDk4_7aBRWOb5XMK99qc1EvKGxCfR8QWMYF9Ps-k"; // 你的完整 token
        // 构建请求
        HttpResponse response = HttpRequest.get(url)
            .header("Host", "api.wbzzsf.com.cn")
            .form("gid", 20378)
            .form("userid", 7502)
            .form("account", "青桔泰富店吧台")
            .form("source", 2)
            .form("uniacid", 20155)
            .form("query", "")  // 注意：Hutool 会自动处理 URL 编码
            .form("pageNum", 1)
            .form("pageSize", 10)
            .form("istemp", 0)
            .form("token", token)
            .execute();
        // 输出结果
        System.out.println("Status: " + response.getStatus());
        System.out.println("Response: " + response.body());
        Map<String,Object> hashMap = JsonUtils.parseObject(response.body(), Map.class);
        System.out.println(hashMap);
    }
}
